<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
<title>KISSY html Parser</title>
</head>
<body>
<script src="/kissy/build/seed-debug.js"></script>
<script src="/kissy/src/package.js"></script>
<label>前：
    <textarea id="before" style="width:80%;height: 300px;">
        <div id="name">
            <!--测试 comment-->
            <span>test</span>
        </div>
    </textarea>
</label>
<br/>
<button id="start">start</button>
<br/>
<label>后：
    <textarea id="after" style="width:80%;height: 300px;"></textarea>
</label>
<script>

    KISSY.use("html-parser,node,util", function (S, HtmlParser,Node,util) {
        var $ = Node.all;
        var start = $("#start");
        start.on("click", function () {
            var basicWriter = new HtmlParser.BasicWriter(),
                    filter = new HtmlParser.Filter(),
                    before = util.trim($("#before").val()),
                    n = new HtmlParser.Parser(before).parse();

            filter.addRules({
                tags:{
                    $:function (el) {
                        S.log(el.tagName);
                    }
                },
                text:function (v) {
                    S.log(v);
                },
                comment:function (v) {
                    S.log(v);
                }
            });
            n.writeHtml(basicWriter, filter);

            $("#after").val(basicWriter.getHtml());
        });
    });
</script>
</body>
</html>